<?php

/**
 * 关注和取消关注
 * User: yaosj
 * Date: 15-10-12
 * Time: 下午3:22
 */
class CollectCareer implements iController {

    public function output($queryArgs) {

        if (validateUser($queryArgs) != 1)
            return genOutput(1000);
        if (empty($queryArgs['uniq_code']) || empty($queryArgs['action']))
            return genOutput(1000);
        global $uddb;

        $userId = intval($queryArgs['user_id']);
        $jobCode = trim($queryArgs['uniq_code']);

        if ('add' == $queryArgs['action']) {
            $sql ='SELECT * FROM user_job_collection u,educms.data_job_major m  WHERE u.user_id = :user_id AND u.status = :status AND u.department_job_code = m.id ';
            //当前年份
            $returnV = require __DIR__ . '/code2name.config.php';
            $curYear = $returnV['current_year'];
            if (isset($curYear))
                $sql .= " AND m.major_year = {$curYear} ";

            $b = $uddb->getResults($sql, array(':user_id' => $userId,':status' => 1));
            if (count($b) >= 10)
                return genOutput(2012);
            $sql ='SELECT * FROM user_job_collection WHERE user_id = :user_id AND department_job_code = :code';
            $a = $uddb->getResults($sql, array(':user_id' => $userId, ':code' => $jobCode));
            //如果不存在，insert
            if (empty($a)) {
                $uddb->insert('user_job_collection',
                    array(
                        'user_id' => $userId,
                        'department_job_code' => $jobCode,
                        'status' => 1,
                        'collect_time' => date('Y-m-d H:i:s'
                        )));
            } else {
                //存在，更新状态
                $uddb->update('user_job_collection', array('status' => 1, 'collect_time' => date('Y-m-d H:i:s', time())), array('user_id' => $userId, 'department_job_code' => $jobCode));
            }
            return genOutput(1);

        } else if ('del' == $queryArgs['action']) {

            $uddb->update('user_job_collection', array('status' => 0, 'collect_time' => date('Y-m-d H:i:s', time())), array('user_id' => $userId, 'department_job_code' => $jobCode));
            return genOutput(1);
        } else {
            return genOutput(1000);
        }
    }
}